home *** CD-ROM | disk | FTP | other *** search
/ Utilities Professional 1-1500 / Utilities Professional 1-1500 (1994)(WPD)[!].iso / 12511500 / var1481.dms / var1481.adf / Extract_Me.LHA / misc / combine.c < prev    next >
C/C++ Source or Header  |  1994-07-07  |  2KB  |  87 lines

  1. /***********************************************************
  2. *
  3. *    This file is Copyright © 1990-1994 Dan Wesnor
  4. *
  5. *    This file and any executables resulting from compilation
  6. *    of this file are freely distributable so long as the
  7. *    above copyright statement is included intact.  This
  8. *    statement of distributability is limited to this file
  9. *    only, and does not include any other file in this
  10. *    archive.
  11. *
  12. *    No gaurantees of usability are made for this file or
  13. *    any executables generated from it.  Use at your own risk.
  14. *
  15. ************************************************************
  16. *
  17. *    This file combines two images into a single image which
  18. *    may be viewed with red/blue 3D glasses (not included).
  19. *    To generate stereo pairs, use MC to generate two images
  20. *    in which everything is the same but is moved slighty to
  21. *    the side in one of these.  Then run them through this
  22. *    program, then through arrt2qrt (found elsewhere in this
  23. *    archive), and finally, use ADPro (or some other program,
  24. *    also not included) to generate a viewable picture.
  25. *
  26. ************************************************************/
  27.  
  28. #include <fcntl.h>
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31.  
  32. far unsigned char lbuff[8192*3], rbuff[8192*3], obuff[8192*3];
  33.  
  34.  
  35. main(int argc, char *argv[])
  36. {
  37.     int    lfh, rfh, ofh,
  38.         xsize, ysize,
  39.         x, y;
  40.  
  41.     if (argc != 4)
  42.     {
  43.         printf("usage: combine leftfile rightfile outfile\n");
  44.         exit(10);
  45.     }
  46.  
  47.     lfh = open(argv[1], O_RDONLY);
  48.     rfh = open(argv[2], O_RDONLY);
  49.     ofh = open(argv[3], O_WRONLY | O_CREAT, 0644);
  50.  
  51.     read(lfh, &xsize, sizeof(int));
  52.     read(lfh, &ysize, sizeof(int));
  53.  
  54.     read(rfh, &x, sizeof(int));
  55.     read(rfh, &y, sizeof(int));
  56.  
  57.     if ((x != xsize) || (y != ysize))
  58.     {
  59.         printf("image sizes do not match");
  60.         exit(10);
  61.     }
  62.  
  63.     write(ofh, &xsize, sizeof(int));
  64.     write(ofh, &ysize, sizeof(int));
  65.  
  66.     for (y=0; y<ysize; y++)
  67.     {
  68.         read(lfh, lbuff, xsize*3);
  69.         read(rfh, rbuff, xsize*3);
  70.  
  71.         for (x=0; x<xsize; x++)
  72.         {
  73.             obuff[x*3] = (lbuff[x*3]+lbuff[x*3+1]+lbuff[x*3+2])/3;
  74.             obuff[x*3+1] = 0;
  75.             obuff[x*3+2] = (rbuff[x*3]+rbuff[x*3+1]+rbuff[x*3+2])/3;
  76.         }
  77.  
  78.         write(ofh, obuff, xsize*3);
  79.     }
  80.  
  81.     close(lfh);
  82.     close(rfh);
  83.     close(ofh);
  84. }
  85.         
  86.     
  87.